<?php 
/**
 * @file			admin.mod.php
 * @CopyRight		(C)1996-2099 SINA Inc.
 * @Project			vyouji
 * @Author			guanghui <guanghui1@staff.sina.com.cn>
 * @Create Date:	2011-10-09
 * @Modified By:	guanghui/2011-10-09
 * @Brief			后台管理员数据模型
 */

include_once(P_MODULES . '/mod.basic.php');

class admin_mod extends modBasic
{
	/**
	 * Brief construct
	 */
	public function __construct()
	{
		parent::__construct(T_ADMIN_USERS);
	}
	
	/**
	* 获取管理员列表
	* 
	* @param int $offset
	* @param int $limit
	*/
	public function getList($offset = 0, $limit = 0)
	{
		return parent::getList(array(), array(), array('admin_id' => 'DESC'), $offset, $limit);
	}
	
	/**
	* 获取管理员数目
	* 
	*/
	public function getCount()
	{
		return parent::getNum();
	}
	
	/**
	* 保存管理员信息
	* 
	* @param array $data
	* @param int $id
	*/
	public function saveInfo($data, $admin_id = '')
	{
		return RST($this->_db->save($data, $admin_id, T_ADMIN_USERS, 'admin_id'));
	}
	
	/**
	* 根据ID获取管理员记录
	* 
	* @param int $admin_id
	*/
	public function getInfoById($admin_id)
	{
		return RST($this->_db->get($admin_id, T_ADMIN_USERS, 'admin_id'));
	}
	
	/**
	* 根据用户名获取管理员记录
	* 
	* @param string $username
	*/
	public function getInfoByName($username)
	{
		return RST($this->_db->get($username, T_ADMIN_USERS, 'username'));
	}
	
	/**
	* 删除一个管理员帐号
	* 
	* @param int $admin_id
	*/
	public function delAdmin($admin_id)
	{
		return RST($this->_db->delete($admin_id, T_ADMIN_USERS, 'admin_id'));
	}
	
	
	/**
	 * 获取管理员分组
	 */
	function getAdminGroup()
	{
		$sql = $this->_db->SQL("Select * From `%s`", $this->_db->getTable(T_ADMIN_GROUP));
		$rst = $this->_db->query($sql);
		
		$result = array();
		if ( is_array($rst) )
		{
			foreach ($rst as $aGroup)
			{
				$result[$aGroup['gid']] = $aGroup;
			}
		}
		return $result;
	}
}